package thinkingInJava;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Queue;
import java.util.Set;
import java.util.Stack;
import java.util.TreeSet;

public class Learn11 {

	public static void main(String[] args) {
		t3();
	}
	//栈方法first in last out
	public static void t3(){
		Stack<String> stack=new Stack<String>();
		stack.push("a");
		stack.push("b");
		stack.pop();
		System.out.println(stack);
	}
	//队列方法first in first out 
	public static void t5(){
		Queue<String> queue;
	}
	public static void t4(){

		Map<String,Object> map=new HashMap<String,Object>();
		map.put("a", "b");
		Set<Entry<String, Object>> set=map.entrySet();
		for (Entry<String, Object> entry : set) {
			System.out.println(entry.getKey()+entry.getValue());
		}
		List<String> list = new ArrayList<String>();
		list.add("a");
		list.add("b");
		list.add("c");
		list.add("d");
		Iterator<String> it = list.iterator();
		while (it.hasNext()) {
			if(it.next().equals("a")){
				it.remove();
			}
		}
		/*
		 * ListIterator<String> lt=list.listIterator(); while(lt.hasNext()){
		 * lt.next(); lt.remove(); }
		 */

		System.out.println(list);
	}
	public static void t1() {
		List<Integer> list = new ArrayList<Integer>();
		Arrays.asList(1, 2, 3, 4, 5);
		list.addAll(Arrays.asList(1, 2, 3, 4, 5));
		System.out.println(list);
		// 这个按照插入的顺序保存
		LinkedHashSet<A> lhs = new LinkedHashSet<A>();
		lhs.add(new A(6));
		lhs.add(new A(2));
		lhs.add(new A(3));
		lhs.add(new A(4));
		lhs.add(new A(5));
		lhs.add(new A(1));
		for (A a : lhs) {
			System.out.println(a.getI());
		}
	}

	public static void t2() {
		// 这个按照对象的升序排序
		TreeSet<CompareB> treeSet = new TreeSet<CompareB>();
		treeSet.add(new CompareB(1, "a"));
		treeSet.add(new CompareB(2, "b"));
		treeSet.add(new CompareB(3, "c"));
		treeSet.add(new CompareB(4, "d"));
		for (CompareB b : treeSet) {
			System.out.println(b.getAge());
		}
	}

}

class CompareB implements Comparable<CompareB> {
	private Integer age;
	private String name;

	public CompareB(Integer age, String name) {
		this.age = age;
		this.name = name;
	}

	public Integer getAge() {
		return age;
	}

	public void setAge(Integer age) {
		this.age = age;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public int compareTo(CompareB o) {
		int i = 0;
		i = this.getAge().compareTo(o.getAge());
		return i == 0 ? this.getName().compareTo(o.getName()) : i;
	}

}

class B {
	private Integer age;
	private String name;

	public Integer getAge() {
		return age;
	}

	public void setAge(Integer age) {
		this.age = age;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
}

class A {
	private Integer i;

	public Integer getI() {
		return i;
	}

	public void setI(Integer i) {
		this.i = i;
	}

	public A(Integer i) {
		this.i = i;
	}
}